const express = require('express');
const router = express.Router();
const warehouseController = require('../controllers/warehouseController');

/**
 * @swagger
 * tags:
 *   name: 仓库管理
 *   description: 仓库信息的增删改查接口
 */

/**
 * @swagger
 * /api/warehouse:
 *   post:
 *     summary: 创建新的仓库
 *     tags: [仓库管理]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name: { type: string }
 *               projectId: { type: integer }
 *               projectName: { type: string }
 *               location: { type: string }
 *               manager: { type: string }
 *               contact: { type: string }
 *               area: { type: number }
 *               capacity: { type: integer }
 *               remark: { type: string }
 *               materialCount: { type: integer }
 *               status: { type: integer }
 *     responses:
 *       200:
 *         description: 创建成功
 *       500:
 *         description: 服务器错误
 */
router.post('/', warehouseController.createWarehouse);

/**
 * @swagger
 * /api/warehouse:
 *   get:
 *     summary: 获取所有仓库
 *     tags: [仓库管理]
 *     responses:
 *       200:
 *         description: 仓库列表
 *       500:
 *         description: 服务器错误
 */
router.get('/', warehouseController.getWarehouses);

/**
 * @swagger
 * /api/warehouse/{id}:
 *   get:
 *     summary: 根据 ID 获取仓库信息
 *     tags: [仓库管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *         description: 仓库ID
 *     responses:
 *       200:
 *         description: 仓库信息
 *       404:
 *         description: 未找到仓库
 *       500:
 *         description: 服务器错误
 */
router.get('/:id', warehouseController.getWarehouseById);

/**
 * @swagger
 * /api/warehouse/{id}:
 *   put:
 *     summary: 更新仓库信息
 *     tags: [仓库管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *         description: 仓库ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name: { type: string }
 *               projectId: { type: integer }
 *               projectName: { type: string }
 *               location: { type: string }
 *               manager: { type: string }
 *               contact: { type: string }
 *               area: { type: number }
 *               capacity: { type: integer }
 *               remark: { type: string }
 *               materialCount: { type: integer }
 *               status: { type: integer }
 *               ended_at: { type: string, format: date-time }
 *     responses:
 *       200:
 *         description: 更新成功
 *       500:
 *         description: 服务器错误
 */
router.put('/:id', warehouseController.updateWarehouse);

/**
 * @swagger
 * /api/warehouse/{id}:
 *   delete:
 *     summary: 删除仓库（软删除）
 *     tags: [仓库管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: integer }
 *         description: 仓库ID
 *     responses:
 *       200:
 *         description: 删除成功
 *       500:
 *         description: 服务器错误
 */
router.delete('/:id', warehouseController.deleteWarehouse);

module.exports = router;
